package com.sig.player;

import com.sig.player.event.PlayerEvent;
import com.sig.player.event.PlayerEventListener;
import com.sig.player.model.AbstractPlayer;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 玩家管理
 *
 * @author sig
 * @since 2019/2/21
 */
public abstract class PlayerManager<T extends AbstractPlayer, L extends PlayerEventListener> {
    @Autowired(required = false)
    protected List<L> playerEventListeners;

    protected void autoInjectionListeners(T player) {
        if (playerEventListeners == null)
            return;
        for (L playerEventListener : playerEventListeners) {
            if (PlayerEventListener.Injection.NORMAL.equals(playerEventListener.injection())) {
                Class<? extends PlayerEvent>[] interestEvents = playerEventListener.interestEvents();
                for (Class<? extends PlayerEvent> playerEventClass : interestEvents) {
                    player.addEventListener(playerEventClass, playerEventListener);
                }
            }
        }
    }
}
